{% extends "main/base.html" %}

{% block title %}查业绩{% endblock %}

{% block content %}
<style>
    
    .sumit-link {
        display: inline-block;
        margin-top: 1rem;
        color: #1a73e8;
        text-decoration: none;
        padding: 0.5rem 1rem;
        border: 1px solid #1a73e8;
        border-radius: 4px;
    }
    .sumit-link:hover {
        background-color: #1a73e8;
        color: white;
    }
</style>

    <h1>业绩查询</h1>
    <p>这里是业绩查询功能区域，{{ username }}。</p>
    
    <!-- 查询表单 -->
    <form method="post" action="{{ url_for('main.performance') }}">
        <div class="form-group">
            <label for="start_date">起始时间:</label>
            <input type="datetime-local" id="start_date" name="start_date" required>
        </div>
        <div class="form-group">
            <label for="end_date">结束时间:</label>
            <input type="datetime-local" id="end_date" name="end_date" required>
        </div>
        <button type="submit" class="sumit-link">查询</button>
        <script>
            // 获取当前日期
            const today = new Date();
            
            // 格式化日期为YYYY-MM-DD格式
            const year = today.getFullYear();
            const month = String(today.getMonth() + 1).padStart(2, '0');
            const day = String(today.getDate()).padStart(2, '0');
            const dateStr = `${year}-${month}-${day}`;
            
            // 设置起始时间为当天00:00
            document.getElementById('startTime').value = `${dateStr}T00:00`;
            
            // 设置结束时间为当天23:59
            document.getElementById('endTime').value = `${dateStr}T23:59`;
        </script>
    </form>

    <!-- 结果展示区域 -->
    {% if performance_data %}
    <h2>查询结果 ({{ start_date }} 至 {{ end_date }})</h2>
    <table border="1">
        <thead>
            <tr>
                <th>店铺名称</th>
                <th>总业绩(元)</th>
            </tr>
        </thead>
        <tbody>
            {% for store in performance_data %}
            <tr>
                <td>{{ store.shop_name }}</td>
                <td>{{ "%.2f"|format(store.total_amount or 0) }}</td>
            </tr>
            {% else %}
            <tr>
                <td colspan="2">没有找到相关数据</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    {% endif %}

    <!-- 错误提示 -->
    {% with messages = get_flashed_messages() %}
      {% if messages %}
        {% for message in messages %}
          <p style="color: red;">{{ message }}</p>
        {% endfor %}
      {% endif %}
    {% endwith %}
{% endblock %}


